package com.cz.ssyx.product.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cz.ssyx.common.result.Result;
import com.cz.ssyx.model.product.SkuInfo;
import com.cz.ssyx.product.service.SkuInfoService;
import com.cz.ssyx.vo.product.SkuInfoQueryVo;
import com.cz.ssyx.vo.product.SkuInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * sku信息 前端控制器
 * </p>
 *
 * @author Joker
 * @since 2024-04-18
 */
@Api(tags = "sku管理")
//@CrossOrigin
@RestController
@RequestMapping("/admin/product/skuInfo")
public class SkuInfoController {

    @Autowired
    private SkuInfoService skuInfoService;

    @ApiOperation("sku列表")
    @GetMapping("/{page}/{limit}")
    public Result getPageList(@PathVariable Long page, @PathVariable Long limit,
                              SkuInfoQueryVo skuInfoQueryVo) {
        Page<SkuInfo> skuInfoPage = new Page<>(page, limit);

        Page<SkuInfo> resultPage = skuInfoService.getPageList(skuInfoPage, skuInfoQueryVo);

        return Result.ok(resultPage);
    }

    @ApiOperation("新增sku商品")
    @PostMapping("/save")
    public Result save(@RequestBody SkuInfoVo skuInfoVo){
        skuInfoService.saveSkuInfo(skuInfoVo);
        return Result.ok(null);
    }

    @ApiOperation("根据id返回商品信息")
    @GetMapping("/get/{id}")
    public Result getById(@PathVariable Long id) {
        SkuInfoVo skuInfovo = skuInfoService.getSkuById(id);
        return Result.ok(skuInfovo);
    }

    @ApiOperation("修改商品信息")
    @PutMapping("/update")
    public Result update(@RequestBody SkuInfoVo skuInfoVo) {
        skuInfoService.updateSku(skuInfoVo);
        return Result.ok(null);
    }

    @ApiOperation("删除商品")
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable Long id) {
        skuInfoService.removeSku(id);
        return Result.ok(null);
    }

    @ApiOperation("批量删除商品")
    @DeleteMapping("/batchRemove")
    public Result batchRemove(@RequestBody List<Long> idList) {
        skuInfoService.batchRemoveSku(idList);
        return Result.ok(null);
    }

    @ApiOperation("商品上架")
    @GetMapping("/publish/{id}/{status}")
    public Result publish(@PathVariable Long id, @PathVariable Integer status) {
        skuInfoService.publishSku(id, status);
        return Result.ok(null);
    }

    @ApiOperation("商品审核")
    @GetMapping("/check/{id}/{status}")
    public Result check(@PathVariable Long id, @PathVariable Integer status) {
        skuInfoService.checkSku(id, status);
        return Result.ok(null);
    }

    @ApiOperation("是否新人专享")
    @GetMapping("/isNewPerson/{id}/{status}")
    public Result isNewPerson(@PathVariable Long id, @PathVariable Integer status) {
        skuInfoService.isNewPersonSku(id, status);
        return Result.ok(null);
    }
}

